/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package deti.es.ukni.cm.persistence;

import deti.es.persistence.account.AccountManagerRemote;
import deti.es.persistence.bandprofile.BandProfileRemote;
import deti.es.persistence.calendar.CalendarManagerRemote;
import deti.es.persistence.network.SocialNetworkRemote;
import javax.ejb.EJB;

/**
 * Data Access Object Factory
 * <p>
 * <code>DAOFactory</code> returns objects for all persistence
 * DAO objects.
 *
 * @author ukni
 */
public class DAOFactory {

    @EJB
    private static AccountManagerRemote AMBean;
    @EJB
    private static CalendarManagerRemote CMBean;
    @EJB
    private static BandProfileRemote BPBean;
    @EJB
    private static SocialNetworkRemote SNBean;

    /**
     * DAO object for AccountManager.
     *
     * @return DAO object.
     *
     * @see AccountManagerRemote
     */
    public static AccountManagerRemote getAccountManager( ){

        if (AMBean == null){
            try{
                javax.naming.Context context = new javax.naming.InitialContext();
                AMBean = (AccountManagerRemote) context.lookup("ejb/MyBandAccountManager");

            } catch( javax.naming.NamingException ex ){
                System.err.println( "Errors found! Unable to lookup service name!" );
                System.err.println( ex.getExplanation() );
            }
        }

        return AMBean;
    }

    /**
     * DAO object for CalendarManager.
     *
     * @return DAO object.
     *
     * @see CalendarManagerRemote
     */
    public static CalendarManagerRemote getCalendarManager( ){

        if (CMBean == null){
            try{
                javax.naming.Context context = new javax.naming.InitialContext();
                CMBean = (CalendarManagerRemote) context.lookup("ejb/MyBandCalendarManager");

            } catch( javax.naming.NamingException ex ){
                System.err.println( "Errors found! Unable to lookup service name!" );
                System.err.println( ex.getExplanation() );
            }
        }

        return CMBean;
    }

    /**
     * DAO object for BandProfile.
     *
     * @return DAO object.
     * 
     * @see BandProfileRemote
     */
    public static BandProfileRemote getBandProfile() {
        if (BPBean == null){
            try{
                javax.naming.Context context = new javax.naming.InitialContext();
                BPBean = (BandProfileRemote) context.lookup("ejb/MyBandBandProfile");

            } catch( javax.naming.NamingException ex ){
                System.err.println( "Errors found! Unable to lookup service name!" );
                System.err.println( ex.getExplanation() );
            }
        }

        return BPBean;
    }

        /**
     * DAO object for SocialNetwork.
     *
     * @return DAO object.
     *
     * @see SocialNetworkRemote
     */
    public static SocialNetworkRemote getSocialNetwork() {
        if (SNBean == null){
            try{
                javax.naming.Context context = new javax.naming.InitialContext();
                SNBean = (SocialNetworkRemote) context.lookup("ejb/MyBandSocialNetwork");

            } catch( javax.naming.NamingException ex ){
                System.err.println( "Errors found! Unable to lookup service name!" );
                System.err.println( ex.getExplanation() );
            }
        }

        return SNBean;
    }

}
